package nc.tb.util.ui;

import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import javax.swing.JOptionPane;

public class NtbDialogUtil {
	public static boolean isTopWindowFrame(Container parentContainer) {
		Window parent = getTopWindow(parentContainer);
		boolean isFrame = parent instanceof Frame;
		return isFrame;
	}

	public static Window getTopWindow(Container parentContainer) {
		Container parent = parentContainer;
		while (parent != null
				&& !(parent instanceof Dialog || parent instanceof Frame)) {

			parent = parent.getParent();
		}

		if (parent == null) {
			parent = JOptionPane.getFrameForComponent(parentContainer);
		}
		return (Window) parent;
	}
}
